<template>
	<view style="height: 100vh; background-color: #FFFFFF;">
		<u-navbar title-color="#FFFFFF" height="48" back-icon-color="#FFFFFF" :border-bottom="false" :is-fixed="true" title="故障详情"></u-navbar>
		<uc-content :loading="loading">
			<view class="list-item">
				<view class="list-bottom">
					<view>工单名称:</view>
					<view>{{falutInfo.name}}</view>
				</view>
			</view>
			<view class="list-item">
				<view class="list-bottom">
					<view>设备名称:</view>
					<view>{{falutInfo.equipmentName}}</view>
				</view>
			</view>
			<view class="list-item">
				<view class="list-bottom">
					<view>所属企业:</view>
					<view>{{falutInfo.enterpriseName}}</view>
				</view>
			</view>
			<view class="list-item">
				<view class="list-bottom">
					<view>所属区域:</view>
					<view>{{falutInfo.regionName}}</view>
				</view>
			</view>
			<view class="list-item">
				<view class="list-bottom">
					<view>故障描述:</view>
					<view>{{falutInfo.remark}}</view>
				</view>
			</view>
			<view class="list-item">
				<view class="list-bottom">
					<view>完成图片:</view>
					<view class="wrap">
						<u-upload :custom-btn="true" @on-success="uploadSuccess" :deletable="false" :max-count="1" ref="uUpload" :show-progress="false" :file-list="fileList" action="/api/admin/aliService/uploadImgAnd">
							<view slot="addBtn" class="slot-btn" hover-class="slot-btn__hover" hover-stay-time="150">
								<u-icon name="photo" size="60" color="#c0c4cc"></u-icon>
							</view>
						</u-upload>
					</view>
				</view>
			</view>
			<view>
				<u-button @click="confirmReceive(falutInfo.ucId)" type="primary" size="medium" v-if="falutInfo.status==1" style="width: 99%;margin-top: 15px;">确认收到工单</u-button>
			</view>
			<view>
				<u-button @click="startExecute(falutInfo.ucId)" type="primary" size="medium" v-if="falutInfo.status==2" style="width: 99%;margin-top: 15px;">到场确认</u-button>
			</view>
			<view>
				<u-button @click="toMaintenanceWorkOrder(falutInfo.ucId)" type="primary" size="medium" v-if="falutInfo.status==3" style="width: 99%;margin-top: 15px;">需维保介入</u-button>
			</view>
			<view>
				<u-button @click="Reporting" type="primary" size="medium" v-if="falutInfo.status==3" style="width: 99%; margin-top: 15px;">反馈整改时间</u-button>
			</view>
			<view>
				<u-button @click="returnWorkOrder(falutInfo.ucId)" type="primary" size="medium" v-if="falutInfo.status==3" style="width: 99%; margin-top: 15px;">退回</u-button>
			</view>
			<view>
				<u-button @click="confirm()" v-if="falutInfo.status==5&&hidden1&&fileList.length<1" type="primary" size="medium" style="width: 99%;margin-top: 15px;">上传完成图片</u-button>
			</view>
		</uc-content>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loading:false,
				falutInfo: {
					
				},
				fileList:[],
				hidden:false,

				hidden1:true,
				ucId:""

			}
		},
		onLoad(e) {
			console.log(e.ucId)
			this.ucId=e.ucId
		},
		onShow() {
			this.initView(this.ucId)
		},
		methods: {
			initView(val) {
				this.loading = false
				this.falutInfo = {
					completeUrl:''
				}
				this.pageNum = 0
				this.getInWorkOrderVo(val)
			},
			getInWorkOrderVo(val) {
				this.utils.request("/api/app/workOrder/getInWorkOrderVo", {	ucId: val}, "post", "app", true).then(res => {
					console.log(res)
					this.falutInfo = res.data
					this.loading=false
					if(this.falutInfo.completeUrl!=null){
						this.fileList=[]
						this.fileList.push({
							url:this.falutInfo.completeUrl
						})
					}
				}).catch(error => {
					console.log(error)
				})
			},
			toMaintenanceWorkOrder(val) {
				this.utils.request("/api/app/workOrder/toMaintenanceWorkOrder", {ucId: val}, "post", "app", true).then(res => {
					this.getInWorkOrderVo(val)
				}).catch(error => {
					console.log(error)
				})
			},
			Reporting(){
				uni.navigateTo({
					url:'/pages/index/workorder/fault/rectificationTime?ucId='+this.falutInfo.ucId,
				})
			},
			returnWorkOrder(val){
				this.utils.request("/api/app/workOrder/workOrderReturn", {ucId: val}, "post", "app", true).then(res => {
					console.log(res)
					uni.navigateTo({
						url:'/pages/index/workorder/fault/list',
					})
				}).catch(error => {
					console.log(error)
				})
			},
			confirmReceive(val){
				this.utils.request("/api/app/workOrder/confirmWorkOrder", {ucId: val}, "post", "app", true).then(res => {
					this.getInWorkOrderVo(val)
				}).catch(error => {
					console.log(error)
				})
			},
			startExecute(val){
				this.utils.request("/api/app/workOrder/startChangeStatus", {ucId: val}, "post", "app", true).then(res => {
					this.getInWorkOrderVo(val)
				}).catch(error => {
					console.log(error)
				})
			},
			uploadSuccess(data, index, lists, name){
				this.falutInfo.completeUrl=data.data
				this.$refs.uUpload.remove(1)
				console.log(this.falutInfo.completeUrl)
				this.confirmEndChangeStatus()
			},
			confirm(){
				console.log("阿斯顿撒")
				this.hidden=true
				this.hidden1=false
			},
			confirmEndChangeStatus(){
				this.utils.request("/api/app/workOrder/confirmEndChangeStatus",this.falutInfo, "post", "app", true).then(res => {
					this.getInWorkOrderVo(this.falutInfo.ucId)

				}).catch(error => {
					console.log(error)
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import "@/uview-ui/libs/css/style.components.scss";
	
	.list-item {
		padding: 20rpx 40rpx;
		background-color: #fff;
		border-bottom: #999999 1px dashed ;
	
		.list-bottom {
			display: flex;
			margin-top: 10rpx;
			font-size: 28rpx;
			justify-content: space-between;
			color: #333;
		}
		.list-center {
			margin-top: 20rpx;
			font-size: 28rpx;
			color: #999999;
		}
	}

	.slot-btn {
			width: 341rpx;
			height: 140rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			background: rgb(244, 245, 246);
			border-radius: 10rpx;
		}

		.slot-btn__hover {
			background-color: rgb(235, 236, 238);
		}

		.pre-box {
			display: flex;
			align-items: center;
			justify-content: space-between;
			flex-wrap: wrap;
		}

		.pre-item {
			flex: 0 0 48.5%;
			border-radius: 10rpx;
			height: 140rpx;
			overflow: hidden;
			position: relative;
			margin-bottom: 20rpx;
		}

		.pre-item-image {
			width: 100%;
			height: 140rpx;
		}
</style>

